import Layout from '@/layout/index.vue'

export const routes = [
  {
    path: '/fileDemo',
    name: 'FileDemo',
    component: () => import('@/views/FileUploadDemo.vue'),
    meta: {
      title: '文件上传示例',
      hidden: true,
    }
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      title: '登录',
      hidden: true,
    }
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/register/index.vue'),
    meta: {
      title: '注册',
      hidden: true,
    }
  },
  {
    path: '/info',
    name: 'Info',
    component: () => import('@/views/info/index.vue'),
    meta: {
      title: '个人中心',
      hidden: true,
    }
  },
  {
    path: '/password',
    name: 'Password',
    component: () => import('@/views/password/index.vue'),
    meta: {
      title: '修改密码',
      hidden: true,
    }
  },
  {
    path: '/',
    name: 'home',
    component: Layout,
    redirect: '/home',
    meta: {
      title: '首页'
    },
    children: [
      {
        path: 'home',
        name: 'home-index',
        component: () => import('@/views/home/index.vue'),
        meta: {
          title: '首页',
          hidden: true,
        }
      }
    ]
  },
  // ...其他前台路由
  // {
  //   path: '/',
  //   name: 'demo',
  //   component: Layout,
  //   redirect: '/demo',
  //   meta: {
  //     title: 'demo'
  //   },
  //   children: [
  //     {
  //       path: 'demo',
  //       name: 'demo-index',
  //       component: () => import('@/views/demo/index.vue'),
  //       meta: {
  //         title: '检测',
  //         hidden: true,
  //       }
  //     },
  //   ]
  // },
  {
    path: '/manager',
    name: 'Manager',
    component: () => import('@/views/manager/nav/index.vue'),
    redirect: '/manager/home',
    meta: {
      title: '后台管理',
      role: 'admin',
      hidden: true,
    },
    children: [
      // 后台管理的路由
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/manager/home/index.vue'),
        meta: {
          title: '首页',
          role: 'admin',
        },
      },
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/manager/user/index.vue'),
        meta: {
          title: '用户管理',
          role: 'admin'
        },
      },
      {
        path: 'log',
        name: 'Log',
        component: () => import('@/views/manager/log/index.vue'),
        meta: {
          title: '日志管理',
          role: 'admin'
        },
      },
      {
        path: 'notice',
        name: 'Notice',
        component: () => import('@/views/manager/notice/index.vue'),
        meta: {
          title: '公告管理',
          role: 'admin'
        },
      },
      // ...其他管理路由
      // {
      //   path: 'demo',
      //   name: 'Demo',
      //   component: () => import('@/views/backend/demo/index.vue'),
      //   meta: {
      //     title: 'Demo',
      //     role: 'admin'
      //   },
      // },
    ]
  },
  {
    path: '/:catchAll(.*)',
    name: 'NotFound',
    meta: {
      name: '无法访问'
    },
    component: () => import('../views/404.vue')
  },
  {
    path: '/403',
    name: 'NoAuth',
    meta: {
      name: '无权访问'
    },
    component: () => import('../views/403.vue')
  }
]

const changeRoutes = (routes) => {
  return routes.reduce((pre, cur) => {
    let item = {
      name: cur.name,
      meta: cur.meta
    }
    if (cur.children && cur.children.length > 0) {
      item.children = changeRoutes(cur.children)
    }
    pre.push(item)
    return pre
  }, [])
}


export const defaultRoutes = changeRoutes(routes)

